package tutorial.lite_mod.comment_sth;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import public_util.model.Const4PublicDataBase;
import public_util.model.PublicAgentInfo;
import public_util.model.PublicMiddleTable;
import public_util.model.ReturnData;
import system_api_4_trade.dao.ApiPublicMiddleTableMapper;
import system_api_4_trade.util.sql.SelectTool;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * 这个类用来提供给before和after方法使用,用于MiddleTable的返回
 */
public class TemplateUtilApi {

    private static Logger logger = Logger.getLogger(TemplateUtilApi.class);





    /**
     * 验证链接: duzikai_api_mgr_public_agent_info?invoke_method=public_page_4m_load_agent_list&id_public_agent_info=99101&is_online=0&pre_cmd_para_show_score_agent_info=true
     * 工具零件方法
     * 组装方法: 主要是在before活着after方法里面调用
     * 根据这个零件来拼装
     * @return
     */
    public static ReturnData pre_cmd_para_show_score_agent_info(List<PublicAgentInfo> agentInfolist, HttpServletRequest request, SqlSession session, HashMap<String, Object> params2db, ReturnData resultData)
    {
        Tutorial4LiteModMapper liteModMapper = session.getMapper(Tutorial4LiteModMapper.class);
        String pre_cmd_para_show_score_agent_info = request.getParameter("pre_cmd_para_show_score_agent_info");
        if ("true".equals(pre_cmd_para_show_score_agent_info))
        {

            if (agentInfolist == null || agentInfolist.size() == 0)
            {
                return null;
            }

            for (int i = 0; i < agentInfolist.size(); i++)
            {
                PublicAgentInfo agentInfo = agentInfolist.get(i);
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put(Const4PublicDataBase.PARA_id_public_agent_info, agentInfo.getId_public_agent_info());
                PublicMiddleTable score = liteModMapper.countShopScore(hashMap);
                if (score == null)
                {
                    agentInfo.setSave_data("");
                }
                else
                {
                    agentInfo.setSave_data(score);
                }


            }


        }
        return null;
    }


}
